package com.tengju.user.domain.model.archive.letax;

import com.tengju.user.domain.model.sign.License;
import com.tengju.user.domain.model.sign.LicenseType;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.shared.AccountId;
import lombok.Value;
import lombok.experimental.NonFinal;

import java.time.LocalDateTime;

@Value
public class LetaxAccount {

    private LetaxAccountId letaxAccountId;

    private UserIdCode userIdCode;

    private AccountId accountId;

    @NonFinal
    private String bankNo;

    @NonFinal
    private String bankName;

    @NonFinal
    private String idCardNo;

    @NonFinal
    private String idCardName;

    @NonFinal
    private String remark;

    @NonFinal
    private LetaxStatus status;

    private String platformCode = "DT";

    @NonFinal
    private LocalDateTime checkTime;

    private LocalDateTime createAt;

    public License license() {
        return new License(LicenseType.IDCARD, idCardNo);
    }

    public boolean isTerminated() {
        return status.getVal() == 3;
    }

    public void check() {
        this.checkTime = LocalDateTime.now();
    }

    public void finish() {
        this.status = LetaxStatus.FINISHED;
    }


    public void failToRelate(String remark) {
        this.status = LetaxStatus.RELATE_FAILED;
        this.remark = remark;
    }


    public void apply() {
        this.status = LetaxStatus.APPLIED;
    }

    public void register() {
        this.status = LetaxStatus.REGISTERED;
    }

    public void failToRegister(String remark) {
        this.status = LetaxStatus.REGISTER_FAILED;
        this.remark = remark;
    }

    public void terminate(String remark) {
        this.status = LetaxStatus.TERMINATED;
        if (remark != null) {
            this.remark = remark;
        }
    }

    public void bindBank(String bankNo, String bankName) {
        this.bankNo = bankNo;
        this.bankName = bankName;
    }

    public void bindIdCard(String idCardNo, String idCardName) {
        this.idCardNo = idCardNo;
        this.idCardName = idCardName;
    }

    public void changeStatus(LetaxStatus updateStatus, String updateRemark) {
        this.status = updateStatus;
        this.remark = updateRemark;
    }
}
